package editor;

import javax.swing.*;

public class Search {
    public int k;  //Record the position of the character you are looking for
    public  void searchtxt( JTextArea TextArea, String str) {
        this.k = 0;
        final String str1, str2, str3, str4, strA, strB;
        str1 = TextArea.getText().replace("\r","");
        str2 = str;
        str3 = str1.toUpperCase();
        str4 = str2.toUpperCase();
        strA = str3;
        strB = str4;

        {
            if (TextArea.getSelectedText() == null){
                this.k = strA.indexOf(strB);
                System.out.println("NO");}
            else
                this.k = strA.indexOf(strB, TextArea.getCaretPosition() - str.length() + 1);
            System.out.println(k);
            if (this.k > -1) { //String strData=strA.subString(k,strB.getText().length()+1);
                TextArea.setCaretPosition(k);
                TextArea.select(k, k + strB.length());
            } else {
                JOptionPane.showMessageDialog(null, "Not Found！", "Find", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }
}
